package br.unicamp.mc933;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class RoutesActivity extends Activity implements OnItemClickListener {
	private static final String TAG = "RoutesActivity";
	ListView listViewRoutes;
	ArrayAdapter<Route> listAdapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.routes);

		Log.d(TAG, "Buscando rotas");

		listViewRoutes = (ListView) findViewById(R.id.listRoutes);
		listViewRoutes.setOnItemClickListener(this);

		Route[] routes = { new Route(1, "Linha 1", "1"),
				new Route(2, "Linha 2", "2"), new Route(3, "Moradia", "3"), };

		listAdapter = new ArrayAdapter<Route>(this, R.layout.routerow, routes);

		Log.d(TAG, "Rotas carregadas");

		listViewRoutes.setAdapter(listAdapter);
	}

	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		Object o = listViewRoutes.getItemAtPosition(arg2);
		Log.d(TAG, "ItemClicked: " + ((Route) o).getId());

		Log.d(TAG, "Iniciando MapsActivity");

		Intent intent = new Intent();
		intent.setClass(this,MapsActivity.class);
		intent.putExtra("route", (Route)o);
		startActivity(intent);
	}
}